<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.HisiPHP.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------

namespace app\system\admin;  

use think\Db; 

/**
 * 用户管理控制器
 * @package app\system\admin
 */
class Yonghu extends Admin
{ 
    /**
     * 用户列表-待安装
     */
    public function index(){ 
        $admin_id = ADMIN_ID;
        $system_user_info = Db::name("system_user")->where("id = '{$admin_id}'")->find();
        if($system_user_info['role_id'] == 1 || $system_user_info['role_id'] == 3){
            $user_list = Db::name('user')->where("status = 0")->paginate(20)->each(function($item, $key){
                $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");;
                return $item;
            });
        }else{
            $user_list = Db::name('user')->where("status = 0 and kf_id = '{$admin_id}'")->paginate(20)->each(function($item, $key){
                $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");;
                return $item;
            }); 
        } 
        $this->assign('user_list', $user_list); 
        return $this->fetch();
    }
    
    /**
     * 已安装列表
     */
    public function indexYaz(){
        $admin_id = ADMIN_ID;
        $system_user_info = Db::name("system_user")->where("id = '{$admin_id}'")->find();
        if($system_user_info['role_id'] == 1 || $system_user_info['role_id'] == 3){
            $user_list = Db::name('user')->where("status = 1")->paginate(20)->each(function($item, $key){
                $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");;
                return $item;
            });
        }else{
            $user_list = Db::name('user')->where("status = 1 and kf_id = '{$admin_id}'")->paginate(20)->each(function($item, $key){
                $item['dlname'] = Db::name("daili")->where("id = '{$item['dl_id']}'")->value("dlname");;
                return $item;
            });
        }
        
        $this->assign('user_list', $user_list);
        return $this->fetch();
    }
    
    /**
     * 确认安装
     */
    public function qraz(){
        $id = $this->request->param('id');
        $res = Db::name('user')->where("id = '{$id}'")->setInc('status');
        if($res){
            $this->success("安装成功！",url('yonghu/index'));
        }else{
            $this->error("安装失败！");
        }
    }
}
